package hn.cch.springboot_redisson.controller;


import hn.cch.springboot_redisson.distributed.DistributedLock;
import hn.cch.springboot_redisson.runnable.LockRunnable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CountDownLatch;


@RequestMapping("/")
@RestController
public class LockController {

    @Autowired
    private DistributedLock distributedLock;

    //十个线程
    private int threadCount = 50;


    @GetMapping("lock")
    public void lock(){
        CountDownLatch countDownLatch = new CountDownLatch(1);
        for (int i = 0; i < threadCount; i++) {
            LockRunnable lockRunnable = new LockRunnable(distributedLock, countDownLatch);
            Thread thread = new Thread(lockRunnable);
            thread.start();
        }
        countDownLatch.countDown();
    }

}
